$(function(){ 
	$("#btnOK").click(function() {
		onDataChange(pageParam);
		
		pageParam.leaseType = 2;
		pageParam.leaseStatus = 1;
		pageParam.totalFee = pageParam.totalMoney;
		pageParam.payWay = parseInt($('input:radio[name="payWay"]:checked').val());
		if((pageParam.payWay==3 || pageParam.payWay==4) && pageParam.officialRent!=0) {
			alert('五保免租金，请在租金实收中输入0');
			return;
		}
		if((pageParam.payWay==4) && pageParam.officialPledge!=0) {
			alert('五保免押金，请在押金实收中输入0');
			return;
		}
		
		if(isEmpty(pageParam.totalMoney)) {
			alert('金额不正确');
			return;
		}
		
		var loginedUser = getLoginedUser();
		if(loginedUser) {
			pageParam.staffId = loginedUser.staffId ;
			pageParam.staffName = loginedUser.staffName;
			pageParam.createTime = loginedUser.createTime;
			pageParam.subjectRoomId = loginedUser.subjectRoomId;
			pageParam.subjectRoomName = loginedUser.subjectRoomName;
		}
		
		save_basic(path+'/lease/save', {lease:pageParam}, function(response) {
			if(response.code=='200') {
				pageParam.createTime = response.data[0].createTime;
				
				if(hasFileToUpload==false) {
					alert('租赁成功');
					var url = '5-1-2ywrent-3.html?pageParam=' + encodeURIComponent(JSON.stringify(pageParam));
					window.open(url);
				}else {
					var options = {  
						url: path+'/accessory/uploadFiles?id='+response.data[0].leaseId,
						type : "post",  
						dataType : 'json',
						
						//提交前处理 
						beforeSubmit: function() {
						},
						
						//处理完成 
						success: function(response_success) {
							if(response_success.code=='200') {
								alert('租赁成功');
								var url = '5-1-2ywrent-3.html?pageParam=' + encodeURIComponent(JSON.stringify(pageParam));
								window.open(url);
							}else {
								alert('文件提交失败');
							}
						}
					};
					
					$('#uploadFileForm').ajaxSubmit(options);
				}
			}else {
				alert('数据提交失败');
			}
		});
	});
});